﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Finances;
@using DCMS.ViewModel.Models.Report;
@using System.Collections.Generic;
@using System.Linq;
@using DCMS.Core.Domain.Common;

@model StaffReportPercentageItemListModel

<section id="content_wrapper">

	<!-- Start: Topbar-Dropdown -->
	<div id="topbar-dropmenu">
		@await Html.PartialAsync("_ToolBox")
	</div>
	<!-- End: Topbar-Dropdown -->
	<!-- Start: Topbar -->
	<header id="topbar">
		<div class="topbar-left">
			<ol class="breadcrumb">
				<li class="crumb-active">
					<a href="#">报表</a>
				</li>
				<li class="crumb-icon">
					<a href="@Url.RouteUrl("HomePage")">
						<span class="glyphicon glyphicon-home"></span>
					</a>
				</li>
				<li class="crumb-link">
					<a href="#">员工报表</a>
				</li>
				<li class="crumb-trail">提成明细表</li>
			</ol>
		</div>
		<div class="topbar-right">
			<div class="ml15 ib va-m" id="toggle_sidemenu_r">
				<a href="#" class="pl5">
					<i class="fa fa-sign-in fs22 text-primary"></i>
					<span class="badge badge-hero badge-danger">3</span>
				</a>
			</div>
		</div>
	</header>
	<!-- End: Topbar -->
	<!-- Begin: Content -->
	<section id="content" class="formSection">

		<div class="special-alerts">
			<div class="alert alert-danger light alert-dismissable" id="alert-demo-2" style="display: none;">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
				<i class="fa fa-info pr10"></i>
				<strong>您没有被授权此操作!</strong>
			</div>
		</div>

		<div class="row">
			<div class="col-md-12">


				<div class="panel">
					<div class="panel-heading">
						<div class="panel-title">
							<span class="glyphicon glyphicon-tasks"></span> 提成明细表
						</div>
					</div>
                    <div class="panel-body p10">

                        <div id="toolbar" class="btn-group mb10">
                            <a href="/StaffReport/StaffReportPercentageSummary" class="btn btn-default btn-sm">
                                <span class="fa fa-undo mr5"></span>返回
                            </a>

                        </div>
                        <div class="pull-right">@("从：" + Model.StartTime)-@("至" + Model.EndTime) @("员工：" + Model.StaffUserName) @("类别：" + Model.CategoryName)  @("商品：" + Model.ProductName)</div>
                        <table class="table table-striped table-bordered table-hover">

                            <tr>
                                <th rowspan="2" class="text-left"><div class="th-inner">商品</div></th>
                                <th rowspan="2" class="text-left"><div class="th-inner">销售分段</div></th>
                                <th rowspan="2" class="text-left"><div class="th-inner">提成方式</div></th>
                                <th colspan="3" class="text-center"><div class="th-inner">提成</div></th>
                                <th colspan="3" class="text-center"><div class="th-inner">数量</div></th>
                                <th colspan="3" class="text-center"><div class="th-inner">金额</div></th>
                                <th colspan="3" class="text-center"><div class="th-inner">利润</div></th>
                            </tr>
                            <tr>
                                <th class="text-right"><div class="th-inner">合计</div></th>
                                <th class="text-right"><div class="th-inner">销售</div></th>
                                <th class="text-right"><div class="th-inner">退货</div></th>
                                <th class="text-right"><div class="th-inner">净销售量</div></th>
                                <th class="text-right"><div class="th-inner">销售</div></th>
                                <th class="text-right"><div class="th-inner">退货</div></th>
                                <th class="text-right"><div class="th-inner">销售净额</div></th>
                                <th class="text-right"><div class="th-inner">销售</div></th>
                                <th class="text-right"><div class="th-inner">退货</div></th>
                                <th class="text-right"><div class="th-inner">净利润</div></th>
                                <th class="text-right"><div class="th-inner">销售</div></th>
                                <th class="text-right"><div class="th-inner">退货</div></th>
                            </tr>

                            @foreach (var item in Model.Items)
                            {
                                <tr>
                                    <td class="text-left">@item.ProductName</td>
                                    <td class="text-center">@item.SaleFragment</td>
                                    <td class="text-left">@item.CalCulateMethodName</td>

                                    <td class="text-right">￥ @item.PercentageTotal.Value.ToString("F2")</td>
                                    <td class="text-right">￥ @item.PercentageSale.Value.ToString("F2")</td>
                                    <td class="text-right">￥ @item.PercentageReturn.Value.ToString("F2")</td>

                                    <td class="text-right">@item.QuantityNetSaleQuantity.Value.ToString("F2")</td>
                                    <td class="text-right">@item.QuantitySale.Value.ToString("F2")</td>
                                    <td class="text-right">@item.QuantityReturn.Value.ToString("F2")</td>

                                    <td class="text-right">￥ @item.AmountSaleNet.Value.ToString("F2")</td>
                                    <td class="text-right">￥ @item.AmountSale.Value.ToString("F2")</td>
                                    <td class="text-right">￥ @item.AmountReturn.Value.ToString("F2")</td>

                                    <td class="text-right">￥ @item.ProfitNet.Value.ToString("F2")</td>
                                    <td class="text-right">￥ @item.ProfitSale.Value.ToString("F2")</td>
                                    <td class="text-right">￥ @item.ProfitReturn.Value.ToString("F2")</td>
                                </tr>
                            }

                            <tr>
                                <td class="text-right" colspan="3"><b>合计:</b></td>

                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.PercentageTotal ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.PercentageSale ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.PercentageReturn ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>@(Model.Items.Select(s => s.QuantityNetSaleQuantity ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>@(Model.Items.Select(s => s.QuantitySale ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>@(Model.Items.Select(s => s.QuantityReturn ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.AmountSaleNet ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.AmountSale ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.AmountReturn ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.ProfitNet ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.ProfitSale ?? 0).Sum().ToString("F2"))</b></td>
                                <td class="text-right"><b>￥ @(Model.Items.Select(s => s.ProfitReturn ?? 0).Sum().ToString("F2"))</b></td>
                            </tr>

                        </table>

                        @{
                            var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                        }

                        @if (!pager.IsEmpty())
                        {
                            <div class="fixed-table-pagination" style="display: block;">
                                @Html.Raw(pager.ToString())
                            </div>
                        }

                    </div>
				</div>
			</div>

		</div>

	</section>

	<!-- End: Content -->
</section>



@await Html.PartialAsync("_Windows", Model)



@{
//Html.AddCssFileParts(ResourceLocation.Head, "~/assets/skin/default_skin/css/theme.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Toastr/toastr.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Tables/bootstrap-table.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/daterange/daterangepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/colorpicker/css/bootstrap-colorpicker.min.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/tagmanager/tagmanager.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/fancytree/skin-win8/ui.fancytree.min.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/Content/Site.css");

}

@section CurPageScripts
{
	@{
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/utility/jquery.sparkline.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.unobtrusive.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/jquery.treegrid.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/locale/bootstrap-table-zh-CN.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table-treegrid.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/globalize.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment-with-locales.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/daterange/daterangepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/datepicker/js/bootstrap-datetimepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/colorpicker/js/bootstrap-colorpicker.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/jquerymask/jquery.maskedinput.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/tagmanager/tagmanager.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/fancytree/jquery.fancytree-all.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/admin-tools/admin-forms/js/advanced/steps/jquery.steps.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Toastr/Toastr.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Custom/Common.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/bootstrap/holder.min.js");
	}
	<script type="text/javascript">

		jQuery(document).ready(function () {

			"use strict";

			// Init Theme Core
			Core.init();

			// Init Demo JS
			Demo.init();

			//权限提示
			if ($(this).getUrlQueryString("Authorize") == "noAuthorize") {
				$('#alert-demo-2').fadeToggle();
				setTimeout(function () {
					$('#alert-demo-2').fadeToggle();
				}, 3000);
			}

			//高级搜索
			$("#panel0 #AdvancedSearch").click(function () {
				var ico = $(this).find(".fa");
				if (ico.hasClass('fa-angle-double-right'))
					ico.removeClass("fa-angle-double-right").addClass("fa-angle-double-down");
				else
					ico.removeClass("fa-angle-double-down").addClass("fa-angle-double-right");
				$("#panel0").find(".panel-body").toggleClass("hidden fadeIn");
			});

			//商品列表选择赋值
			window.operateEventsPop = {
				'click .rowSelect': function (e, value, row, index) {
					var index = $(this).attr("data-id");
					var keys = Object.keys(row.Units);
					$("#ProductName").val(row.Name);
					$("#ProductId").val(row.Id);
					$('#ModalProductWindows').modal('hide');
				}
			};
			$("#btn_search_product").click(function () {
				$(this).productSelectShowModal($("#ModalProductWindows"), "/Product/AsyncSearchSelectPopup", null, "选择商品", $("#ProductModalForm"),
					function () { });
			});

			//客户搜索
			$(document).on('click', "#btn_search_customer", function () {
				var actionUrl = "/Terminal/AsyncSearchSelectPopup";
				$(this).showModalV2($("#TerminalSelectModalWindow"), actionUrl, { ids: "" }, "选择终端", $("#TerminalSelectForm"), function (rows) { });
			});

			window.operateEventsPopTerminal = {
				'click .rowSelect': function (e, value, row, index) {
					try {
						$("#TerminalId").val(row.Id);
						$("#TerminalName").val(row.Name);
						$('#TerminalSelectModalWindow').modal('hide');
					}
					catch (err) {
						console.log(err);
						$(this).showToastr(err);
						return;
					}
				}
			};

			//防止重复查询
			var queryNumber = 1;
			$("#btn_query").click(function () {
				if (queryNumber > 1) {
					return false;
				}
				queryNumber = queryNumber + 1;
			});

		});
	</script>
}